<script setup lang="ts">
import { ref } from 'vue';

// 家庭成员数据
const familyMembers = ref([
  { id: 1, surname: '李', name: '李四', relation: '父亲', healthStatus: '需随访', avatar: '李' },
  { id: 2, surname: '张', name: '张三', relation: '本人', healthStatus: '正常', avatar: '张' },
  { id: 3, surname: '王', name: '王五', relation: '母亲', healthStatus: '正常', avatar: '王' },
]);

// 健康报告数据
const healthReports = ref([
  { name: '年龄风险', value: '中', count: 0 },
  { name: '家族遗传风险', value: '高', count: 1 },
  { name: '慢性病风险', value: '低', count: 0 },
  { name: '体重指数', value: '正常', count: 2 },
]);
</script>

<template>
  <div class="family-health-profile">
    <!-- 左侧：成员健康共建区域 -->
    <div class="profile-section members-section">
      <h3>成员健康共建</h3>
      <div class="members-list">
        <div v-for="member in familyMembers" :key="member.id" class="member-card">
          <div class="member-info">
            <div class="avatar">{{ member.avatar }}</div>
            <div class="details">
              <div class="name">{{ member.name }}</div>
              <div class="relation">{{ member.relation }}</div>
              <div class="health-status">
                健康状态: <span :class="['status', member.healthStatus === '正常' ? 'normal' : 'warning']">{{ member.healthStatus }}</span>
              </div>
            </div>
          </div>
          <div class="actions">
            <span class="close-btn">×</span>
          </div>
        </div>
      </div>
    </div>

    <!-- 右侧：家族病史图谱 -->
    <div class="profile-section family-history-section">
      <h3>家族病史图谱</h3>
      <div class="history-graph">
        <!-- 这里可以使用SVG或Canvas绘制家族病史图谱 -->
        <div class="graph-placeholder">
          <!-- 简单模拟图谱效果 -->
          <div class="graph-container">
            <div v-for="i in 20" :key="i" class="node" :style="{
              left: `${Math.random() * 80 + 10}%`,
              top: `${Math.random() * 80 + 10}%`,
              width: `${Math.random() * 30 + 20}px`,
              height: `${Math.random() * 30 + 20}px`,
              opacity: Math.random() * 0.5 + 0.3
            }"></div>
            <div class="node main-node"></div>
            <!-- 连线 -->
            <svg class="connections" width="100%" height="100%">
              <line v-for="i in 25" :key="i"
                :x1="Math.random() * 100 + '%'"
                :y1="Math.random() * 100 + '%'"
                :x2="Math.random() * 100 + '%'"
                :y2="Math.random() * 100 + '%'"
                stroke="#ccc"
                stroke-width="1"
                opacity="0.3" />
            </svg>
          </div>
        </div>
      </div>
    </div>

    <!-- 底部：家庭健康报告 -->
    <div class="profile-section health-report-section">
      <h3>家庭健康报告</h3>
      <div class="report-items">
        <div v-for="(report, index) in healthReports" :key="index" class="report-item">
          <div class="report-name">{{ report.name }}</div>
          <div class="report-value" :class="{
            'high-risk': report.value === '高',
            'medium-risk': report.value === '中',
            'low-risk': report.value === '低',
            'normal': report.value === '正常'
          }">
            {{ report.value }}
            <span class="count" v-if="report.count > 0">{{ report.count }}人</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.family-health-profile {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 20px;
  padding: 20px;
}

.profile-section {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  padding: 15px;
}

.members-section {
  grid-column: 1;
  grid-row: 1;
}

.family-history-section {
  grid-column: 2;
  grid-row: 1;
}

.health-report-section {
  grid-column: 1 / span 2;
  grid-row: 2;
}

h3 {
  margin-top: 0;
  margin-bottom: 15px;
  font-size: 18px;
  color: #333;
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
}

/* 成员卡片样式 */
.members-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.member-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  background-color: #f9f9f9;
  border: 1px solid #eee;
}

.member-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
}

.details {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.name {
  font-weight: bold;
  font-size: 16px;
}

.relation {
  font-size: 12px;
  color: #666;
}

.health-status {
  font-size: 14px;
}

.status {
  font-weight: bold;
}

.status.normal {
  color: #52c41a;
}

.status.warning {
  color: #faad14;
}

.close-btn {
  font-size: 20px;
  color: #999;
  cursor: pointer;
}

/* 家族病史图谱样式 */
.history-graph {
  height: 300px;
  position: relative;
}

.graph-placeholder {
  width: 100%;
  height: 100%;
  background-color: #f5f5f5;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}

.graph-container {
  width: 100%;
  height: 100%;
  position: relative;
}

.node {
  position: absolute;
  border-radius: 50%;
  background-color: #91d5ff;
  z-index: 2;
}

.main-node {
  width: 40px;
  height: 40px;
  background-color: #1890ff;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
}

.connections {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}

/* 健康报告样式 */
.report-items {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

.report-item {
  width: 23%;
  padding: 15px;
  background-color: #f9f9f9;
  border-radius: 4px;
  margin-bottom: 10px;
}

.report-name {
  font-size: 14px;
  color: #666;
  margin-bottom: 5px;
}

.report-value {
  font-size: 16px;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.high-risk {
  color: #f5222d;
}

.medium-risk {
  color: #faad14;
}

.low-risk {
  color: #52c41a;
}

.normal {
  color: #1890ff;
}

.count {
  font-size: 12px;
  color: #999;
  font-weight: normal;
}
</style>